<template>
  <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="userAccount"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="userPassword"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
    <van-field
      v-model="checkPassword"
      type="password"
      label="请再输入密码"
      placeholder="二次密码"
      :rules="[{ required: true, message: '请填写二次密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      注册
    </van-button>
  </div>
</van-form>
</template>





<script setup lang="ts">
import {ref} from 'vue'
import myAxios from '../../plugins/myAxios';
import {useRouter} from 'vue-router'
import { showSuccessToast, showFailToast } from 'vant';

const router = useRouter()

const userAccount = ref('');
const userPassword = ref('');
const checkPassword = ref('');
const onSubmit = async() => {
  const res = await myAxios.post('/user/register',{
    userAccount:userAccount.value,
    userPassword:userPassword.value,
    checkPassword:checkPassword.value
  })
  if(res.data.code===0 && res.data ){
    showSuccessToast('注册成功');
    router.replace('/user/login')
  }else{
    showFailToast('注册失败')
  }
};





</script>



<style scoped>

</style>
